<?php

namespace App\Http\Requests\System\Position;

use Illuminate\Foundation\Http\FormRequest;

class StoreResource extends FormRequest
{
	/**
	 * 授权认证
	 *
	 * Date: 22/03/2018
	 * @author George
	 * @return bool
	 */
    public function authorize()
    {
        $user = $this->user('user');

        if ($user && $user->manager && $user->company_id) {
        	// 请求中追加参数
        	$this->offsetSet('company_id', $user->company_id);
        	return true;
		}
		return false;
    }

	/**
	 * 定义验证规则
	 *
	 * Date: 22/03/2018
	 * @author George
	 * @return array
	 */
    public function rules()
    {
        return [
        	'name' => 'required',
			'permissions' => 'required|array'
        ];
    }

	/**
	 * 定义验证规则提示
	 *
	 * Date: 22/03/2018
	 * @author George
	 * @return array
	 */
	public function messages()
	{
		return [
			'name.required' => '请输入岗位名称',
			'permissions.array' => '参数必须为权限ID构成的数组',
		];
    }
}
